package com.wutong.eams.interfaces;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public interface PageAttributeSetting {

    HttpServletRequest getRequest();

    HttpServletResponse getResponse();

    void setRequestAndResponse(HttpServletRequest request, HttpServletResponse response);

    default void setSessionAttribute(String key, Object value) {
        getRequest().getSession().setAttribute(key, value);
    }

    default <T> T getSessionAttribute(String key, Class<T> type) {
        return type.cast(getRequest().getSession().getAttribute(key));
    }

    default void removeSessionAttribute(String key) {
        getRequest().getSession().removeAttribute(key);
    }

    default void setRequestAttribute(String key, Object value) {
        getRequest().setAttribute(key, value);
    }

    default <T> T getRequestAttribute(String key, Class<T> type) {
        return type.cast(getRequest().getAttribute(key));
    }

    default void removeRequestAttribute(String key) {
        getRequest().removeAttribute(key);
    }

}
